package com.vnl.system.aaa.service;

import com.vnl.system.aaa.util.AAErrCode;
import com.vnl.system.aaa.util.AARuntimeException;

public class AAAServiceFactory {

    private static AAAServiceFactory instance;
    
    private IAAService iaaService;
    private ICompanyService companyService;
    private IEntityCreator entityCreator;
    private IUserService userService;
    private IRoleService roleService;
    private ISystemService systemService;
    
    private AAAServiceFactory() {
        
    }
    
    public static AAAServiceFactory getInstance() {
        if (instance == null) {
            instance = new AAAServiceFactory();
        }
        return instance;
    }
    
    public void setAAservice(IAAService service) {
        this.iaaService = service;
    }
    
    public IAAService getAAService() {
        if (this.iaaService == null) {
            throw new AARuntimeException(AAErrCode.AA_ENV_SETUP_ERROR_IAASERVICE_NOT_SET);
        }
        return this.iaaService;
    }
    
    public void setCompanyService(ICompanyService companyService) {
    	this.companyService = companyService;
    }
    
    public ICompanyService getCompanyService() {
    	if (this.companyService == null) {
    		throw new AARuntimeException(AAErrCode.AA_ENV_SETUP_ERROR_IAASERVICE_NOT_SET);
    	}
    	return this.companyService;
    }

	public void clear() {
		this.iaaService = null;
		this.companyService = null;
		this.roleService = null;
	}

	public IEntityCreator getEntityCreator() {
		if (this.entityCreator == null) {
			throw new AARuntimeException(AAErrCode.AA_ENV_SETUP_ERROR_IENTITYCREATOR_NOT_SET);
		}
		return entityCreator;
	}

	public void setEntityCreator(IEntityCreator entityCreator) {
		this.entityCreator = entityCreator;
	}

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
	public IRoleService getRoleService() {
		return roleService;
	}
	
	public void setRoleService(IRoleService roleService) {
		this.roleService = roleService;
	}

	public ISystemService getSystemService() {
		return systemService;
	}
	
	public void setSystemService(ISystemService systemService) {
		this.systemService = systemService;
	}
}
